﻿using AspectInjector.Broker;
using System;
using System.Collections.Generic;
using System.Text;

namespace MQ.Core.Cache
{
   // [Aspect(Scope.Global,Factory =typeof(CacheAttributeFactory)]
    [Injection(typeof(CacheAspect))]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public sealed class CacheAttribute : Attribute
    {
        public string Key { get; set; }
        public bool Delete { get; set; }
        //private ICache cache = CacheFactory.Redis();
        public CacheAttribute(string key,bool delete)
        {
            this.Key = key;
            this.Delete = delete;
        }
        //[Advice(Kind.Around)]
        //public object Handle([Argument(Source.ReturnType)]Type type, [Argument(Source.Target)]Func<object[], object> method, [Argument(Source.Arguments)] object[] arguments, [Argument(Source.Triggers)] Attribute[] triggers)

        //{
        //    this.Key=triggers[0].
        //    if (!Delete)
        //    {
        //        var data = cache.Get<object>(Key);
        //        if (data != null) return data;
        //        else
        //        {
        //            var result = method(arguments);
        //            cache.Set<object>(Key, result);
        //            return result;
        //        }
        //    }
        //    else
        //    {
        //        var result = method(arguments);
        //        cache.Remove(Key);
        //        return null;
        //    }
        //}
    }
}
